package team.seekers.hula.user.user.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import team.seekers.hula.common.entity.UserSessionDTO;
import team.seekers.hula.common.entity.enums.user.RoleEnum;
import team.seekers.hula.common.entity.enums.user.SexEnum;

import java.io.Serializable;
import java.util.Date;

/**
 * @author hbc
 * @since 2021-02-15
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "user对象", description = "用户表")
@TableName(value = "user")
public class UserDO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户openID")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    @ApiModelProperty(value = "用户账号")
    private String account;

    @ApiModelProperty(value = "用户账号")
    private String unionId;

    @ApiModelProperty(value = "用户账号")
    private String openIdMap;

    @ApiModelProperty(value = "电话号码")
    private String tel;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "用户角色")
    @JsonValue
    private RoleEnum role;

    @ApiModelProperty(value = "用户学校id")
    private String schoolId;

    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "用户个人页面背景图")
    private String background;

    @ApiModelProperty(value = "用户个性签名")
    private String summary;

    @ApiModelProperty(value = "性别")
    @JsonValue
    private SexEnum sex;

    @ApiModelProperty(value = "用户课表")
    private String classTable;

    @TableLogic
    private Integer isDeleted;

    @TableField(fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    public static UserSessionDTO toSessionDTO(UserDO userDO) {
        System.out.println("log"+userDO.getRole().getName());
        return UserSessionDTO.builder()
                .id(userDO.getId())
                .account(userDO.getAccount())
                .tel(userDO.getTel())
                .nickname(userDO.getNickname())
                .role(userDO.getRole().getName())
                .build();
    }

}
